package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.ZcAppliance;
import com.ruoyi.system.service.IZcApplianceService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 办公家具，器具Controller
 * 
 * @author ruoyi
 * @date 2023-06-26
 */
@Controller
@RequestMapping("/system/appliance")
public class ZcApplianceController extends BaseController
{
    private String prefix = "system/appliance";

    @Autowired
    private IZcApplianceService zcApplianceService;

    @RequiresPermissions("system:appliance:view")
    @GetMapping()
    public String appliance()
    {
        return prefix + "/appliance";
    }

    /**
     * 查询办公家具，器具列表
     */
    @RequiresPermissions("system:appliance:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ZcAppliance zcAppliance)
    {
        startPage();
        List<ZcAppliance> list = zcApplianceService.selectZcApplianceList(zcAppliance);
        return getDataTable(list);
    }

    /**
     * 导出办公家具，器具列表
     */
    @RequiresPermissions("system:appliance:export")
    @Log(title = "办公家具，器具", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ZcAppliance zcAppliance)
    {
        List<ZcAppliance> list = zcApplianceService.selectZcApplianceList(zcAppliance);
        ExcelUtil<ZcAppliance> util = new ExcelUtil<ZcAppliance>(ZcAppliance.class);
        return util.exportExcel(list, "办公家具，器具数据");
    }

    /**
     * 新增办公家具，器具
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存办公家具，器具
     */
    @RequiresPermissions("system:appliance:add")
    @Log(title = "办公家具，器具", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ZcAppliance zcAppliance)
    {
        return toAjax(zcApplianceService.insertZcAppliance(zcAppliance));
    }

    /**
     * 修改办公家具，器具
     */
    @RequiresPermissions("system:appliance:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ZcAppliance zcAppliance = zcApplianceService.selectZcApplianceById(id);
        mmap.put("zcAppliance", zcAppliance);
        return prefix + "/edit";
    }

    /**
     * 修改保存办公家具，器具
     */
    @RequiresPermissions("system:appliance:edit")
    @Log(title = "办公家具，器具", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ZcAppliance zcAppliance)
    {
        return toAjax(zcApplianceService.updateZcAppliance(zcAppliance));
    }

    /**
     * 删除办公家具，器具
     */
    @RequiresPermissions("system:appliance:remove")
    @Log(title = "办公家具，器具", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(zcApplianceService.deleteZcApplianceByIds(ids));
    }
}
